package com.cnap.model.stage;

import cn.hutool.core.text.CharSequenceUtil;

/**
 * 阶段二级分类
 *
 * @author xc
 **/
public enum StageDetailTypeEnum {
    // 注释
    ONE_ONE("1-1", StageTypeEnum.CLOUD_RESOURCE.getType(), 1, "申请云资源，完成开通"),
    // 注释
    ONE_TWO("1-2", StageTypeEnum.CLOUD_RESOURCE.getType(), 2, "获取开通的云资源详情"),
    // 注释
    TOW_ONE("2-1", StageTypeEnum.SAFE_PORT.getType(), 1, "确认需要开通的端口"),
    // 注释
    TOW_TOW("2-2", StageTypeEnum.SAFE_PORT.getType(), 2, "申请端口开通"),
    // 注释
    TOW_THREE("2-3", StageTypeEnum.SAFE_PORT.getType(), 3, "等待端口开通完成"),
    // 注释
    TOW_FOUR("2-4", StageTypeEnum.SAFE_PORT.getType(), 4, "完成端口开通确认"),
    // 注释
    THREE_ONE("3-1", StageTypeEnum.K8S.getType(), 1, "检查云资源状态"),
    // 注释
    THREE_TOW("3-2", StageTypeEnum.K8S.getType(), 2, "拉取安装所需资源"),
    // 注释
    THREE_THREE("3-3", StageTypeEnum.K8S.getType(), 3, "确认安装环境"),
    // 注释
    THREE_FOUR("3-4", StageTypeEnum.K8S.getType(), 4, "安装openssh，ansible等软件"),
    // 注释
    THREE_FIVE("3-5", StageTypeEnum.K8S.getType(), 5, "配置安装参数"),
    // 注释
    THREE_SIX("3-6", StageTypeEnum.K8S.getType(), 6, "完成K8s/Prometheus镜像库同步设置"),
    // 注释
    THREE_SEVEN("3-7", StageTypeEnum.K8S.getType(), 7, "完成K8s集群节点标签设置"),
    // 注释
    FOUR_ONE("4-1", StageTypeEnum.DISTRIBUTE.getType(), 1, "完成应用镜像同步"),
    // 注释
    FOUR_TOW("4-2", StageTypeEnum.DISTRIBUTE.getType(), 2, "完成应用安装部署"),

    // 注释
    UNKNOWN("--", "unknown", 0, "unknown"),
    ;

    private final String detailType;
    private final String parentType;
    private final int order;
    private final String message;

    StageDetailTypeEnum(String detailType, String parentType, int order, String message) {
        this.detailType = detailType;
        this.parentType = parentType;
        this.order = order;
        this.message = message;
    }

    /**
     * get
     *
     * @return DetailType
     */
    public String getDetailType() {
        return detailType;
    }

    /**
     * get
     *
     * @return ParentType
     */
    public String getParentType() {
        return parentType;
    }

    /**
     * get
     *
     * @return Order
     */
    public int getOrder() {
        return order;
    }

    /**
     * get
     *
     * @return Message
     */
    public String getMessage() {
        return message;
    }

    /**
     * 获取当前枚举的前一个枚举值
     *
     * @return 结果
     */
    public StageDetailTypeEnum previous() {
        int ordinal = this.ordinal();
        StageDetailTypeEnum[] stageTypeEnums = StageDetailTypeEnum.values();
        for (StageDetailTypeEnum stageTypeEnum : stageTypeEnums) {
            if (stageTypeEnum.ordinal() == ordinal - 1) {
                return stageTypeEnum;
            }
        }
        return UNKNOWN;
    }

    /**
     * 获取当前枚举的后一个枚举值
     *
     * @return 结果
     */
    public StageDetailTypeEnum next() {
        int ordinal = this.ordinal();
        StageDetailTypeEnum[] stageTypeEnums = StageDetailTypeEnum.values();
        for (StageDetailTypeEnum stageTypeEnum : stageTypeEnums) {
            if (stageTypeEnum.ordinal() == ordinal + 1) {
                return stageTypeEnum;
            }
        }
        return UNKNOWN;
    }

    /**
     * 根据类型获取枚举
     *
     * @param type 类型
     * @return 结果
     */
    public static StageDetailTypeEnum getStageDetailTypeEnumByType(String type) {
        if (CharSequenceUtil.isEmpty(type)) {
            return UNKNOWN;
        }
        StageDetailTypeEnum[] stageTypeEnums = StageDetailTypeEnum.values();
        for (StageDetailTypeEnum stageTypeEnum : stageTypeEnums) {
            if (stageTypeEnum.getDetailType().equals(type)) {
                return stageTypeEnum;
            }
        }
        return UNKNOWN;
    }
}
